<?php
namespace app\admin\controller;

use app\common\model\AuthorWxUser as AuthorWxUserModel;
use app\common\controller\AdminBase;
use think\Session;

class Distribution extends AdminBase
{
    protected $author_wx_user;
    protected $author_config;

    protected function _initialize()
    {
        parent::_initialize();
        $this->author_config = session::get('wechat_info');
        $this->author_wx_user = new AuthorWxUserModel();
    }

    public function index(){
        $type = $this->author_wx_user->where('id',$this->author_config['id'])->value('distribute_type');
        $this->assign('type',$type);
        return $this->fetch();
    }

    public function updateDistributeType(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $result = $this->author_wx_user->save(['distribute_type' => $data['type']],['id' => $this->author_config['id']]);
            if($result){
                return json(['status' => 1,'msg' => 'ok']);
            }else{
                return json(['status' => -1 , 'error' => 'update type error']);
            }
        }
    }
}